/**
 * 
 */
package com.alstudio.core.iaj;

import android.text.TextPaint;
import android.text.TextUtils;
import android.text.style.URLSpan;
import android.view.View;

/**
 * @author alonso lee
 * 
 */
public class ALUrlSpan extends URLSpan {

	private String mUrl = null;
	private ALUrlClickListener mListener;

	// 缺省超链颜色为黑色
	private int colorStr = android.R.color.black;

	public ALUrlSpan(String url, int colorStr) {
		super(url);
		this.mUrl = url;
		setColorStr(colorStr);
	}

	public ALUrlSpan(String url, ALUrlClickListener listener) {
		super(url);
		this.mUrl = url;
		this.mListener = listener;
	}

	public ALUrlSpan(String url, int colorStr, ALUrlClickListener listener) {
		super(url);
		this.mUrl = url;
		this.mListener = listener;
		setColorStr(colorStr);
	}

	/**
	 * 设置超链点击事件监听器
	 * 
	 * @param mListener
	 *            the mListener to set
	 */
	public void setUrlClickListener(ALUrlClickListener mListener) {
		this.mListener = mListener;
	}

	public void setParseUrl(String url) {
		this.mUrl = url;
	}

	public String getParseUrl() {
		return mUrl;
	}

	public int getColorStr() {
		return colorStr;
	}

	public void setColorStr(int colorStr) {
		this.colorStr = colorStr;
	}

	@Override
	public void updateDrawState(TextPaint ds) {
		super.updateDrawState(ds);
		ds.setUnderlineText(false);
		ds.setColor(colorStr);
	}

	@Override
	public void onClick(View widget) {
		// TODO Auto-generated method stub
		if (!TextUtils.isEmpty(mUrl)) {
			if (mListener != null) {
				mListener.onUrlClick(mUrl);
			}
		}
	}

}
